home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1610 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Fastest way to index thru an array????
  5. Date: 11 Jan 1996 19:27:00 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4d3oa4$uj@clarknet.clark.net>
  8. References: <4d1g3k$o09@solaris.cc.vt.edu> <4d34p7$kj9@tahko.lpr.carel.fi>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. Ari Lukumies (aril@cmt.lpr.mail.carel.fi) wrote:
  16. : Try this:
  17. :     double    *p = A;
  18. :     for (i = 0; i < 50*60*70; i++)
  19. :         *p++ = <some expression>;
  20. : BTW, array indexes in C/C++ begin at 0, _not_ at 1.
  21.  
  22. !!!!!  NO  !!!!!
  23.  
  24. A is a constant pointer to an array of 50 pointers, each of which points 
  25. to an array of 60 pointers, each of which points to an array of 70 
  26. doubles. The arrays of doubles are not necessarily contiguous, and A does 
  27. not point to any of them.
  28.  
  29. A is (double const ***). p is (double *). If p, which points to doubles, 
  30. is assigned the value of A, which points to pointers, we have gibberish.
  31.  
  32. The original writer's solution is almost the most efficient possible, the 
  33. most efficient being the one with pointer iteration that has already been 
  34. left here as a response by someone else. That solution substitutes 
  35. incrementing for addition in each pass through the loop.
  36.